package com.xusiyan08.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;

@RestController
public class LoadBalancerController {

    private static final AtomicInteger counter = new AtomicInteger(0);
    private static final int[] PORTS = {8083, 8084};

    @GetMapping("/get-port")
    public String getLoadBalancedPort() {
        int index = counter.getAndIncrement() % PORTS.length;
        int port = PORTS[index];
        System.out.println("Current load balanced port: " + port);
        return "Using port: " + port;
    }
}